package com.craftplay.dao;

import com.craftplay.model.Unit;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;


@Mapper
public interface UnitMapper {
    @Delete({
            "delete from unit",
            "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
            "insert into unit ( `user_id`, `kind`, `title`, `content`, `image`, `latitude`, `longitude`, `name`, `address`, `scope`, `form`, ",
            "`least_course_num`, `least_price`, `price`, `max_person`, `date`, `time_len`, `tool`, `young_or_old`, `join_num`, `is_public`, `tel`,",
            " `addr`, `traffic`, `status`,`created_time`,`update_time`, `anonymous`, `focusSee`, `paySee`, `payMoney`, `typeId`, `coverUrl`, `fileId`,",
            " `mediaUrl`, `parentId`, `mediaLength`,`isRead`,`viewNum`,`classType`,`classTreeType`,`classMoney`,`askUserId`)",
            "values (#{userId,jdbcType=INTEGER}, ",
            "#{kind,jdbcType=INTEGER}, #{title,jdbcType=VARCHAR}, #{content,jdbcType=VARCHAR}, ",
            "#{image,jdbcType=VARCHAR}, #{latitude,jdbcType=DOUBLE}, ",
            "#{longitude,jdbcType=DOUBLE}, #{name,jdbcType=VARCHAR}, ",
            "#{address,jdbcType=VARCHAR}, #{scope,jdbcType=VARCHAR}, ",
            "#{form,jdbcType=INTEGER}, #{leastCourseNum,jdbcType=INTEGER}, ",
            "#{leastPrice,jdbcType=INTEGER}, #{price,jdbcType=INTEGER}, ",
            "#{maxPerson,jdbcType=INTEGER}, #{date,jdbcType=VARCHAR}, ",
            "#{timeLen,jdbcType=INTEGER}, #{tool,jdbcType=VARCHAR}, #{youngOrOld,jdbcType=INTEGER}, ",
            "#{joinNum,jdbcType=INTEGER}, #{isPublic,jdbcType=INTEGER}, ",
            "#{tel,jdbcType=VARCHAR}, #{addr,jdbcType=VARCHAR}, #{traffic,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER}, ",
            "#{createdTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP},",
            "#{anonymous,jdbcType=INTEGER}, #{focusSee,jdbcType=INTEGER}, #{paySee,jdbcType=INTEGER}, #{payMoney,jdbcType=DOUBLE},",
            "#{typeId,jdbcType=INTEGER},#{coverUrl,jdbcType=VARCHAR},#{fileId,jdbcType=VARCHAR},",
            "#{mediaUrl,jdbcType=VARCHAR},#{parentId,jdbcType=INTEGER},#{mediaLength,jdbcType=INTEGER},#{isRead,jdbcType=INTEGER},#{viewNum,jdbcType=INTEGER},",
            "#{classType,jdbcType=INTEGER},#{classTreeType,jdbcType=INTEGER},#{classMoney,jdbcType=INTEGER},#{askUserId,jdbcType=INTEGER})"
    })
    @SelectKey(statement = "select LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = int.class)
    @Options(useGeneratedKeys = true,keyProperty = "id")
    int insert(Unit record);


    List<Unit> selectUnit(@Param("address") String address, @Param("kind") int kind, @Param("scope") String scope, @Param("latitude") double latitude, @Param("longitude") double longitude);

    List<Unit> selectUnitOrderByTime(@Param("address") String address, @Param("kind") int kind, @Param("scope") String scope);

    List<Unit> selectUnitOrderByTimeAndCondition(@Param("address") String address, @Param("kind") int kind, @Param("scope") String scope);

    List<Unit> selectUnitByCondition(@Param("address") String address, @Param("kind") int kind, @Param("scope") String scope, @Param("latitude") double latitude, @Param("longitude") double longitude);

    List<Unit> selectUnitDesc(@Param("address") String address, @Param("kind") int kind, @Param("scope") String scope, @Param("latitude") double latitude, @Param("longitude") double longitude);

    List<Unit> selectUnitByConditionDesc(@Param("address") String address, @Param("kind") int kind, @Param("scope") String scope, @Param("latitude") double latitude, @Param("longitude") double longitude);

    List<Unit> selectUnitByPriceAsc(@Param("address") String address, @Param("kind") int kind, @Param("scope") String scope);

    List<Unit> selectUnitByPriceAscT(@Param("address") String address, @Param("kind") int kind, @Param("scope") String scope);

    List<Unit> selectUnitByPriceDesc(@Param("address") String address, @Param("kind") int kind, @Param("scope") String scope);

    List<Unit> selectUnitByPriceDescT(@Param("address") String address, @Param("kind") int kind, @Param("scope") String scope);


    @Select({
            "select * ",
            "from unit",
            "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "user_id", property = "userId", jdbcType = JdbcType.INTEGER),
            @Result(column = "kind", property = "kind", jdbcType = JdbcType.INTEGER),
            @Result(column = "title", property = "title", jdbcType = JdbcType.VARCHAR),
            @Result(column = "content", property = "content", jdbcType = JdbcType.VARCHAR),
            @Result(column = "image", property = "image", jdbcType = JdbcType.VARCHAR),
            @Result(column = "latitude", property = "latitude", jdbcType = JdbcType.DOUBLE),
            @Result(column = "longitude", property = "longitude", jdbcType = JdbcType.DOUBLE),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "address", property = "address", jdbcType = JdbcType.VARCHAR),
            @Result(column = "scope", property = "scope", jdbcType = JdbcType.VARCHAR),
            @Result(column = "form", property = "form", jdbcType = JdbcType.INTEGER),
            @Result(column = "least_course_num", property = "leastCourseNum", jdbcType = JdbcType.INTEGER),
            @Result(column = "least_price", property = "leastPrice", jdbcType = JdbcType.INTEGER),
            @Result(column = "price", property = "price", jdbcType = JdbcType.INTEGER),
            @Result(column = "max_person", property = "maxPerson", jdbcType = JdbcType.INTEGER),
            @Result(column = "date", property = "date", jdbcType = JdbcType.VARCHAR),
            @Result(column = "time_len", property = "timeLen", jdbcType = JdbcType.INTEGER),
            @Result(column = "tool", property = "tool", jdbcType = JdbcType.VARCHAR),
            @Result(column = "young_or_old", property = "youngOrOld", jdbcType = JdbcType.INTEGER),
            @Result(column = "join_num", property = "joinNum", jdbcType = JdbcType.INTEGER),
            @Result(column = "is_public", property = "isPublic", jdbcType = JdbcType.INTEGER),
            @Result(column = "tel", property = "tel", jdbcType = JdbcType.VARCHAR),
            @Result(column = "addr", property = "addr", jdbcType = JdbcType.VARCHAR),
            @Result(column = "traffic", property = "traffic", jdbcType = JdbcType.VARCHAR),
            @Result(column = "created_time", property = "createdTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "update_time", property = "updateTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "anonymous", property = "anonymous", jdbcType = JdbcType.INTEGER),
            @Result(column = "focusSee", property = "focusSee", jdbcType = JdbcType.INTEGER),
            @Result(column = "paySee", property = "paySee", jdbcType = JdbcType.INTEGER),
            @Result(column = "payMoney", property = "payMoney", jdbcType = JdbcType.DOUBLE),
            @Result(column = "typeId", property = "typeId", jdbcType = JdbcType.INTEGER),
            @Result(column = "coverUrl", property = "coverUrl", jdbcType = JdbcType.VARCHAR),
            @Result(column = "fileId", property = "fileId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "mediaUrl", property = "mediaUrl", jdbcType = JdbcType.VARCHAR),
            @Result(column = "parentId", property = "parentId", jdbcType = JdbcType.INTEGER),
            @Result(column = "classType", property = "classType", jdbcType = JdbcType.INTEGER),
            @Result(column = "classTreeType", property = "classTreeType", jdbcType = JdbcType.VARCHAR),
            @Result(column = "classMoney", property = "classMoney", jdbcType = JdbcType.INTEGER),
            @Result(column = "askUserId", property = "askUserId", jdbcType = JdbcType.INTEGER)
    })
    Unit selectByPrimaryKey(Integer id);

    @Select({
            "select * ",
            "from unit",
            "order by created_time"
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "user_id", property = "userId", jdbcType = JdbcType.INTEGER),
            @Result(column = "kind", property = "kind", jdbcType = JdbcType.INTEGER),
            @Result(column = "title", property = "title", jdbcType = JdbcType.VARCHAR),
            @Result(column = "content", property = "content", jdbcType = JdbcType.VARCHAR),
            @Result(column = "image", property = "image", jdbcType = JdbcType.VARCHAR),
            @Result(column = "latitude", property = "latitude", jdbcType = JdbcType.DOUBLE),
            @Result(column = "longitude", property = "longitude", jdbcType = JdbcType.DOUBLE),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "address", property = "address", jdbcType = JdbcType.VARCHAR),
            @Result(column = "scope", property = "scope", jdbcType = JdbcType.VARCHAR),
            @Result(column = "form", property = "form", jdbcType = JdbcType.INTEGER),
            @Result(column = "least_course_num", property = "leastCourseNum", jdbcType = JdbcType.INTEGER),
            @Result(column = "least_price", property = "leastPrice", jdbcType = JdbcType.INTEGER),
            @Result(column = "price", property = "price", jdbcType = JdbcType.INTEGER),
            @Result(column = "max_person", property = "maxPerson", jdbcType = JdbcType.INTEGER),
            @Result(column = "date", property = "date", jdbcType = JdbcType.VARCHAR),
            @Result(column = "time_len", property = "timeLen", jdbcType = JdbcType.INTEGER),
            @Result(column = "tool", property = "tool", jdbcType = JdbcType.VARCHAR),
            @Result(column = "young_or_old", property = "youngOrOld", jdbcType = JdbcType.INTEGER),
            @Result(column = "join_num", property = "joinNum", jdbcType = JdbcType.INTEGER),
            @Result(column = "is_public", property = "isPublic", jdbcType = JdbcType.INTEGER),
            @Result(column = "tel", property = "tel", jdbcType = JdbcType.VARCHAR),
            @Result(column = "addr", property = "addr", jdbcType = JdbcType.VARCHAR),
            @Result(column = "traffic", property = "traffic", jdbcType = JdbcType.VARCHAR),
            @Result(column = "created_time", property = "createdTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "update_time", property = "updateTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "status", property = "status", jdbcType = JdbcType.INTEGER),
            @Result(column = "anonymous", property = "anonymous", jdbcType = JdbcType.INTEGER),
            @Result(column = "focusSee", property = "focusSee", jdbcType = JdbcType.INTEGER),
            @Result(column = "paySee", property = "paySee", jdbcType = JdbcType.INTEGER),
            @Result(column = "payMoney", property = "payMoney", jdbcType = JdbcType.DOUBLE),
            @Result(column = "typeId", property = "typeId", jdbcType = JdbcType.INTEGER),
            @Result(column = "coverUrl", property = "coverUrl", jdbcType = JdbcType.VARCHAR),
            @Result(column = "fileId", property = "fileId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "mediaUrl", property = "mediaUrl", jdbcType = JdbcType.VARCHAR),
            @Result(column = "parentId", property = "parentId", jdbcType = JdbcType.INTEGER),
            @Result(column = "askUserId", property = "askUserId", jdbcType = JdbcType.INTEGER)
    })
    List<Unit> findAll();

    List<Unit> findAllByKind(@Param(value = "kind") int kind, @Param(value = "scope") String scope, @Param(value = "address") String address);


    @Select({
            "select *",
            "from unit",
            "where user_id = #{userId,jdbcType=INTEGER} and kind < 8 order by created_time desc"
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "user_id", property = "userId", jdbcType = JdbcType.INTEGER),
            @Result(column = "kind", property = "kind", jdbcType = JdbcType.INTEGER),
            @Result(column = "title", property = "title", jdbcType = JdbcType.VARCHAR),
            @Result(column = "content", property = "content", jdbcType = JdbcType.VARCHAR),
            @Result(column = "image", property = "image", jdbcType = JdbcType.VARCHAR),
            @Result(column = "latitude", property = "latitude", jdbcType = JdbcType.DOUBLE),
            @Result(column = "longitude", property = "longitude", jdbcType = JdbcType.DOUBLE),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "address", property = "address", jdbcType = JdbcType.VARCHAR),
            @Result(column = "scope", property = "scope", jdbcType = JdbcType.VARCHAR),
            @Result(column = "form", property = "form", jdbcType = JdbcType.INTEGER),
            @Result(column = "least_course_num", property = "leastCourseNum", jdbcType = JdbcType.INTEGER),
            @Result(column = "least_price", property = "leastPrice", jdbcType = JdbcType.INTEGER),
            @Result(column = "price", property = "price", jdbcType = JdbcType.INTEGER),
            @Result(column = "max_person", property = "maxPerson", jdbcType = JdbcType.INTEGER),
            @Result(column = "date", property = "date", jdbcType = JdbcType.VARCHAR),
            @Result(column = "time_len", property = "timeLen", jdbcType = JdbcType.INTEGER),
            @Result(column = "tool", property = "tool", jdbcType = JdbcType.VARCHAR),
            @Result(column = "young_or_old", property = "youngOrOld", jdbcType = JdbcType.INTEGER),
            @Result(column = "join_num", property = "joinNum", jdbcType = JdbcType.INTEGER),
            @Result(column = "is_public", property = "isPublic", jdbcType = JdbcType.INTEGER),
            @Result(column = "tel", property = "tel", jdbcType = JdbcType.VARCHAR),
            @Result(column = "addr", property = "addr", jdbcType = JdbcType.VARCHAR),
            @Result(column = "traffic", property = "traffic", jdbcType = JdbcType.VARCHAR),
            @Result(column = "created_time", property = "createdTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "update_time", property = "updateTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "anonymous", property = "anonymous", jdbcType = JdbcType.INTEGER),
            @Result(column = "focusSee", property = "focusSee", jdbcType = JdbcType.INTEGER),
            @Result(column = "paySee", property = "paySee", jdbcType = JdbcType.INTEGER),
            @Result(column = "payMoney", property = "payMoney", jdbcType = JdbcType.DOUBLE),
            @Result(column = "typeId", property = "typeId", jdbcType = JdbcType.INTEGER),
            @Result(column = "coverUrl", property = "coverUrl", jdbcType = JdbcType.VARCHAR),
            @Result(column = "fileId", property = "fileId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "mediaUrl", property = "mediaUrl", jdbcType = JdbcType.VARCHAR),
            @Result(column = "parentId", property = "parentId", jdbcType = JdbcType.INTEGER),
            @Result(column = "mediaLength", property = "mediaLength", jdbcType = JdbcType.INTEGER),
            @Result(column = "askUserId", property = "askUserId", jdbcType = JdbcType.INTEGER)
    })
    List<Unit> selectByUser(int userId);

    @Select({
            "select *",
            "where address = #{address,jdbcType=VARCHAR} order by created_time"
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "user_id", property = "userId", jdbcType = JdbcType.INTEGER),
            @Result(column = "kind", property = "kind", jdbcType = JdbcType.INTEGER),
            @Result(column = "title", property = "title", jdbcType = JdbcType.VARCHAR),
            @Result(column = "content", property = "content", jdbcType = JdbcType.VARCHAR),
            @Result(column = "image", property = "image", jdbcType = JdbcType.VARCHAR),
            @Result(column = "latitude", property = "latitude", jdbcType = JdbcType.DOUBLE),
            @Result(column = "longitude", property = "longitude", jdbcType = JdbcType.DOUBLE),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "address", property = "address", jdbcType = JdbcType.VARCHAR),
            @Result(column = "scope", property = "scope", jdbcType = JdbcType.VARCHAR),
            @Result(column = "form", property = "form", jdbcType = JdbcType.INTEGER),
            @Result(column = "least_course_num", property = "leastCourseNum", jdbcType = JdbcType.INTEGER),
            @Result(column = "least_price", property = "leastPrice", jdbcType = JdbcType.INTEGER),
            @Result(column = "price", property = "price", jdbcType = JdbcType.INTEGER),
            @Result(column = "max_person", property = "maxPerson", jdbcType = JdbcType.INTEGER),
            @Result(column = "date", property = "date", jdbcType = JdbcType.VARCHAR),
            @Result(column = "time_len", property = "timeLen", jdbcType = JdbcType.INTEGER),
            @Result(column = "tool", property = "tool", jdbcType = JdbcType.VARCHAR),
            @Result(column = "young_or_old", property = "youngOrOld", jdbcType = JdbcType.INTEGER),
            @Result(column = "join_num", property = "joinNum", jdbcType = JdbcType.INTEGER),
            @Result(column = "is_public", property = "isPublic", jdbcType = JdbcType.INTEGER),
            @Result(column = "tel", property = "tel", jdbcType = JdbcType.VARCHAR),
            @Result(column = "addr", property = "addr", jdbcType = JdbcType.VARCHAR),
            @Result(column = "traffic", property = "traffic", jdbcType = JdbcType.VARCHAR),
            @Result(column = "created_time", property = "createdTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "update_time", property = "updateTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "anonymous", property = "anonymous", jdbcType = JdbcType.INTEGER),
            @Result(column = "focusSee", property = "focusSee", jdbcType = JdbcType.INTEGER),
            @Result(column = "paySee", property = "paySee", jdbcType = JdbcType.INTEGER),
            @Result(column = "payMoney", property = "payMoney", jdbcType = JdbcType.DOUBLE),
            @Result(column = "typeId", property = "typeId", jdbcType = JdbcType.INTEGER),
            @Result(column = "coverUrl", property = "coverUrl", jdbcType = JdbcType.VARCHAR),
            @Result(column = "fileId", property = "fileId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "mediaUrl", property = "mediaUrl", jdbcType = JdbcType.VARCHAR),
            @Result(column = "parentId", property = "parentId", jdbcType = JdbcType.INTEGER),
            @Result(column = "mediaLength", property = "mediaLength", jdbcType = JdbcType.INTEGER),
            @Result(column = "askUserId", property = "askUserId", jdbcType = JdbcType.INTEGER)
    })
    List<Unit> selectByPlaceAndScrope(@Param("place") String place, @Param("scope") String scope);


    //页面获取所有获得
    List<Unit> getUnitList(Unit unit);


    //获得所有回复
    @Select({
            "select *",
            "from unit",
            "where  FIND_IN_SET(id, getChildLst(#{unitId,jdbcType=INTEGER})) and kind=11;"
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "user_id", property = "userId", jdbcType = JdbcType.INTEGER),
            @Result(column = "kind", property = "kind", jdbcType = JdbcType.INTEGER),
            @Result(column = "title", property = "title", jdbcType = JdbcType.VARCHAR),
            @Result(column = "content", property = "content", jdbcType = JdbcType.VARCHAR),
            @Result(column = "image", property = "image", jdbcType = JdbcType.VARCHAR),
            @Result(column = "latitude", property = "latitude", jdbcType = JdbcType.DOUBLE),
            @Result(column = "longitude", property = "longitude", jdbcType = JdbcType.DOUBLE),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "address", property = "address", jdbcType = JdbcType.VARCHAR),
            @Result(column = "scope", property = "scope", jdbcType = JdbcType.VARCHAR),
            @Result(column = "form", property = "form", jdbcType = JdbcType.INTEGER),
            @Result(column = "least_course_num", property = "leastCourseNum", jdbcType = JdbcType.INTEGER),
            @Result(column = "least_price", property = "leastPrice", jdbcType = JdbcType.INTEGER),
            @Result(column = "price", property = "price", jdbcType = JdbcType.INTEGER),
            @Result(column = "max_person", property = "maxPerson", jdbcType = JdbcType.INTEGER),
            @Result(column = "date", property = "date", jdbcType = JdbcType.VARCHAR),
            @Result(column = "time_len", property = "timeLen", jdbcType = JdbcType.INTEGER),
            @Result(column = "tool", property = "tool", jdbcType = JdbcType.VARCHAR),
            @Result(column = "young_or_old", property = "youngOrOld", jdbcType = JdbcType.INTEGER),
            @Result(column = "join_num", property = "joinNum", jdbcType = JdbcType.INTEGER),
            @Result(column = "is_public", property = "isPublic", jdbcType = JdbcType.INTEGER),
            @Result(column = "tel", property = "tel", jdbcType = JdbcType.VARCHAR),
            @Result(column = "addr", property = "addr", jdbcType = JdbcType.VARCHAR),
            @Result(column = "traffic", property = "traffic", jdbcType = JdbcType.VARCHAR),
            @Result(column = "created_time", property = "createdTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "update_time", property = "updateTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "anonymous", property = "anonymous", jdbcType = JdbcType.INTEGER),
            @Result(column = "focusSee", property = "focusSee", jdbcType = JdbcType.INTEGER),
            @Result(column = "paySee", property = "paySee", jdbcType = JdbcType.INTEGER),
            @Result(column = "payMoney", property = "payMoney", jdbcType = JdbcType.DOUBLE),
            @Result(column = "typeId", property = "typeId", jdbcType = JdbcType.INTEGER),
            @Result(column = "coverUrl", property = "coverUrl", jdbcType = JdbcType.VARCHAR),
            @Result(column = "fileId", property = "fileId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "mediaUrl", property = "mediaUrl", jdbcType = JdbcType.VARCHAR),
            @Result(column = "parentId", property = "parentId", jdbcType = JdbcType.INTEGER),
            @Result(column = "mediaLength", property = "mediaLength", jdbcType = JdbcType.INTEGER),
            @Result(column = "askUserId", property = "askUserId", jdbcType = JdbcType.INTEGER)
    })
    List<Unit> getUnitReplyList(Integer unitId);


    //获得所有指点
    @Select({
            "select *",
            "from unit",
            "where  FIND_IN_SET(id, getChildLst(#{unitId,jdbcType=INTEGER})) and kind=8;"
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "user_id", property = "userId", jdbcType = JdbcType.INTEGER),
            @Result(column = "kind", property = "kind", jdbcType = JdbcType.INTEGER),
            @Result(column = "title", property = "title", jdbcType = JdbcType.VARCHAR),
            @Result(column = "content", property = "content", jdbcType = JdbcType.VARCHAR),
            @Result(column = "image", property = "image", jdbcType = JdbcType.VARCHAR),
            @Result(column = "latitude", property = "latitude", jdbcType = JdbcType.DOUBLE),
            @Result(column = "longitude", property = "longitude", jdbcType = JdbcType.DOUBLE),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "address", property = "address", jdbcType = JdbcType.VARCHAR),
            @Result(column = "scope", property = "scope", jdbcType = JdbcType.VARCHAR),
            @Result(column = "form", property = "form", jdbcType = JdbcType.INTEGER),
            @Result(column = "least_course_num", property = "leastCourseNum", jdbcType = JdbcType.INTEGER),
            @Result(column = "least_price", property = "leastPrice", jdbcType = JdbcType.INTEGER),
            @Result(column = "price", property = "price", jdbcType = JdbcType.INTEGER),
            @Result(column = "max_person", property = "maxPerson", jdbcType = JdbcType.INTEGER),
            @Result(column = "date", property = "date", jdbcType = JdbcType.VARCHAR),
            @Result(column = "time_len", property = "timeLen", jdbcType = JdbcType.INTEGER),
            @Result(column = "tool", property = "tool", jdbcType = JdbcType.VARCHAR),
            @Result(column = "young_or_old", property = "youngOrOld", jdbcType = JdbcType.INTEGER),
            @Result(column = "join_num", property = "joinNum", jdbcType = JdbcType.INTEGER),
            @Result(column = "is_public", property = "isPublic", jdbcType = JdbcType.INTEGER),
            @Result(column = "tel", property = "tel", jdbcType = JdbcType.VARCHAR),
            @Result(column = "addr", property = "addr", jdbcType = JdbcType.VARCHAR),
            @Result(column = "traffic", property = "traffic", jdbcType = JdbcType.VARCHAR),
            @Result(column = "created_time", property = "createdTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "update_time", property = "updateTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "anonymous", property = "anonymous", jdbcType = JdbcType.INTEGER),
            @Result(column = "focusSee", property = "focusSee", jdbcType = JdbcType.INTEGER),
            @Result(column = "paySee", property = "paySee", jdbcType = JdbcType.INTEGER),
            @Result(column = "payMoney", property = "payMoney", jdbcType = JdbcType.DOUBLE),
            @Result(column = "typeId", property = "typeId", jdbcType = JdbcType.INTEGER),
            @Result(column = "coverUrl", property = "coverUrl", jdbcType = JdbcType.VARCHAR),
            @Result(column = "fileId", property = "fileId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "mediaUrl", property = "mediaUrl", jdbcType = JdbcType.VARCHAR),
            @Result(column = "parentId", property = "parentId", jdbcType = JdbcType.INTEGER),
            @Result(column = "mediaLength", property = "mediaLength", jdbcType = JdbcType.INTEGER),
            @Result(column = "askUserId", property = "askUserId", jdbcType = JdbcType.INTEGER)
    })
    List<Unit> getUnitDirectionsList(Integer unitId);


    /**
     * 获取所有父节点
     *
     * @param parentId
     * @return
     */
    @Select({
            "select * ",
            "from unit",
            "where parentId = #{parentId,jdbcType=INTEGER}",
            "order by created_time"
    })
    List<Unit> findAllByParentId(int parentId);


    /**
     * 查看次数加1
     *
     * @param unitId
     */
    @Update({
            "update unit set viewNum=viewNum+1 where id = #{unitId}"
    })
    void addViewNum(int unitId);


    List<Unit> findAllByFocusUserId(@Param(value = "userId") List<Integer> userId, @Param(value = "scope") String scope, @Param(value = "address") String address);

    List<Unit> findAllByUnitList(@Param(value = "unitList") List<Integer> unitList);

    List<Unit> findAllByMyKind(@Param(value = "kindList") List<Integer> kindList, @Param(value = "userId") Integer userId, @Param(value = "scope") String scope, @Param(value = "address") String address, @Param(value = "anonymous") Boolean anonymous);


    //获得所有未读消息
    @Select({
            "select *",
            "from unit",
            "where  FIND_IN_SET(id, getChildLst(#{unitId,jdbcType=INTEGER})) and isRead=#{isRead} order by created_time desc "
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "user_id", property = "userId", jdbcType = JdbcType.INTEGER),
            @Result(column = "kind", property = "kind", jdbcType = JdbcType.INTEGER),
            @Result(column = "title", property = "title", jdbcType = JdbcType.VARCHAR),
            @Result(column = "content", property = "content", jdbcType = JdbcType.VARCHAR),
            @Result(column = "image", property = "image", jdbcType = JdbcType.VARCHAR),
            @Result(column = "latitude", property = "latitude", jdbcType = JdbcType.DOUBLE),
            @Result(column = "longitude", property = "longitude", jdbcType = JdbcType.DOUBLE),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "address", property = "address", jdbcType = JdbcType.VARCHAR),
            @Result(column = "scope", property = "scope", jdbcType = JdbcType.VARCHAR),
            @Result(column = "form", property = "form", jdbcType = JdbcType.INTEGER),
            @Result(column = "least_course_num", property = "leastCourseNum", jdbcType = JdbcType.INTEGER),
            @Result(column = "least_price", property = "leastPrice", jdbcType = JdbcType.INTEGER),
            @Result(column = "price", property = "price", jdbcType = JdbcType.INTEGER),
            @Result(column = "max_person", property = "maxPerson", jdbcType = JdbcType.INTEGER),
            @Result(column = "date", property = "date", jdbcType = JdbcType.VARCHAR),
            @Result(column = "time_len", property = "timeLen", jdbcType = JdbcType.INTEGER),
            @Result(column = "tool", property = "tool", jdbcType = JdbcType.VARCHAR),
            @Result(column = "young_or_old", property = "youngOrOld", jdbcType = JdbcType.INTEGER),
            @Result(column = "join_num", property = "joinNum", jdbcType = JdbcType.INTEGER),
            @Result(column = "is_public", property = "isPublic", jdbcType = JdbcType.INTEGER),
            @Result(column = "tel", property = "tel", jdbcType = JdbcType.VARCHAR),
            @Result(column = "addr", property = "addr", jdbcType = JdbcType.VARCHAR),
            @Result(column = "traffic", property = "traffic", jdbcType = JdbcType.VARCHAR),
            @Result(column = "created_time", property = "createdTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "update_time", property = "updateTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "anonymous", property = "anonymous", jdbcType = JdbcType.INTEGER),
            @Result(column = "focusSee", property = "focusSee", jdbcType = JdbcType.INTEGER),
            @Result(column = "paySee", property = "paySee", jdbcType = JdbcType.INTEGER),
            @Result(column = "payMoney", property = "payMoney", jdbcType = JdbcType.DOUBLE),
            @Result(column = "typeId", property = "typeId", jdbcType = JdbcType.INTEGER),
            @Result(column = "coverUrl", property = "coverUrl", jdbcType = JdbcType.VARCHAR),
            @Result(column = "fileId", property = "fileId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "mediaUrl", property = "mediaUrl", jdbcType = JdbcType.VARCHAR),
            @Result(column = "parentId", property = "parentId", jdbcType = JdbcType.INTEGER),
            @Result(column = "mediaLength", property = "mediaLength", jdbcType = JdbcType.INTEGER),
            @Result(column = "isRead", property = "isRead", jdbcType = JdbcType.INTEGER),
            @Result(column = "askUserId", property = "askUserId", jdbcType = JdbcType.INTEGER)
    })
    List<Unit> getMyRead(@Param(value = "unitId") Integer unitId, @Param(value = "isRead") Integer isRead);


    //获得所有消息
    @Select({
            "SELECT tmp2.* FROM unit tmp1 LEFT JOIN unit tmp2 ON tmp1.id=tmp2.parentId WHERE tmp1.user_id=#{userId} and tmp2.parentId!=-1. order by tmp2.isRead, tmp2.created_time desc "
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "user_id", property = "userId", jdbcType = JdbcType.INTEGER),
            @Result(column = "kind", property = "kind", jdbcType = JdbcType.INTEGER),
            @Result(column = "title", property = "title", jdbcType = JdbcType.VARCHAR),
            @Result(column = "content", property = "content", jdbcType = JdbcType.VARCHAR),
            @Result(column = "image", property = "image", jdbcType = JdbcType.VARCHAR),
            @Result(column = "latitude", property = "latitude", jdbcType = JdbcType.DOUBLE),
            @Result(column = "longitude", property = "longitude", jdbcType = JdbcType.DOUBLE),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "address", property = "address", jdbcType = JdbcType.VARCHAR),
            @Result(column = "scope", property = "scope", jdbcType = JdbcType.VARCHAR),
            @Result(column = "form", property = "form", jdbcType = JdbcType.INTEGER),
            @Result(column = "least_course_num", property = "leastCourseNum", jdbcType = JdbcType.INTEGER),
            @Result(column = "least_price", property = "leastPrice", jdbcType = JdbcType.INTEGER),
            @Result(column = "price", property = "price", jdbcType = JdbcType.INTEGER),
            @Result(column = "max_person", property = "maxPerson", jdbcType = JdbcType.INTEGER),
            @Result(column = "date", property = "date", jdbcType = JdbcType.VARCHAR),
            @Result(column = "time_len", property = "timeLen", jdbcType = JdbcType.INTEGER),
            @Result(column = "tool", property = "tool", jdbcType = JdbcType.VARCHAR),
            @Result(column = "young_or_old", property = "youngOrOld", jdbcType = JdbcType.INTEGER),
            @Result(column = "join_num", property = "joinNum", jdbcType = JdbcType.INTEGER),
            @Result(column = "is_public", property = "isPublic", jdbcType = JdbcType.INTEGER),
            @Result(column = "tel", property = "tel", jdbcType = JdbcType.VARCHAR),
            @Result(column = "addr", property = "addr", jdbcType = JdbcType.VARCHAR),
            @Result(column = "traffic", property = "traffic", jdbcType = JdbcType.VARCHAR),
            @Result(column = "created_time", property = "createdTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "update_time", property = "updateTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "anonymous", property = "anonymous", jdbcType = JdbcType.INTEGER),
            @Result(column = "focusSee", property = "focusSee", jdbcType = JdbcType.INTEGER),
            @Result(column = "paySee", property = "paySee", jdbcType = JdbcType.INTEGER),
            @Result(column = "payMoney", property = "payMoney", jdbcType = JdbcType.DOUBLE),
            @Result(column = "typeId", property = "typeId", jdbcType = JdbcType.INTEGER),
            @Result(column = "coverUrl", property = "coverUrl", jdbcType = JdbcType.VARCHAR),
            @Result(column = "fileId", property = "fileId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "mediaUrl", property = "mediaUrl", jdbcType = JdbcType.VARCHAR),
            @Result(column = "parentId", property = "parentId", jdbcType = JdbcType.INTEGER),
            @Result(column = "mediaLength", property = "mediaLength", jdbcType = JdbcType.INTEGER),
            @Result(column = "isRead", property = "isRead", jdbcType = JdbcType.INTEGER),
            @Result(column = "askUserId", property = "askUserId", jdbcType = JdbcType.INTEGER)
    })
    List<Unit> getMyMessage(@Param(value = "userId") Integer userId);

    @Update({
            "update unit",
            "set ",
            "isRead = 1",
            "where id = #{id,jdbcType=INTEGER}"
    })
    void updateUnRead(Integer id);

    List<Unit> getUnitByUserId(Unit unit);

    List<Unit> findAllByClassGroupByUserId(@Param(value = "scope") String scope, @Param(value = "address") String address);

    List<Unit> findClassByUserId(@Param(value = "userId") Integer userId, @Param(value = "scope") String scope, @Param(value = "address") String address, @Param(value = "limit") int limit);



    int updateByPrimaryKeySelective(Unit unit);

    int updateByPage(Unit unit);
}